package com.ziven.common.widget.app;

import android.app.Activity;
import android.content.Intent;
import android.view.View;

import androidx.annotation.NonNull;

import com.ziven.easygo.EasyGos;
import com.ziven.easygo.autowired.EasyGo;
import com.ziven.easygo.overall.IDispatch;
import com.ziven.easygo.ui.ViewProvider;
import com.ziven.easygo.util.Carry;
import com.ziven.easygo.util.DataProvider;
import com.ziven.easygo.util.MapDataProvider;
import com.ziven.easygo.util.ResourceUtils;

import java.util.List;
import java.util.Map;

/**
 * @author Ziven
 */
public final class EasyUtil {

    private EasyUtil() {}

    public static EasyGo easyGo() {
        return EasyGo.get();
    }

    public static void easyGo(@NonNull Class<?> cls) {
        EasyGo.easyGo(cls);
    }

    public static void easyGo(@NonNull Intent intent) {
        EasyGo.easyGo(ResourceUtils.getContext(), intent);
    }

    public static void easyGo(@NonNull Carry<Intent> carry) {
        Intent intent = new Intent();
        carry.carry(intent);
        EasyGo.easyGo(ResourceUtils.getContext(), intent);
    }

    public static void easyGo(@NonNull Activity activity,
                              @NonNull Class<?> cls,
                              int requestCode) {
        EasyGo.easyGo(activity, cls, requestCode);
    }

    public static void easyGo(@NonNull Activity activity,
                              @NonNull Intent intent,
                              int requestCode) {
        EasyGo.easyGo(activity, intent, requestCode);
    }

    public static void easyGo(@NonNull Activity activity,
                              @NonNull Carry<Intent> carry,
                              int requestCode) {
        Intent intent = new Intent();
        carry.carry(intent);
        EasyGo.easyGo(activity, intent, requestCode);
    }

    @NonNull
    public static IDispatch getDispatch() {
        return EasyGos.getDispatch();
    }

    public static <V extends View> ViewProvider<V> viewProvider() {
        return ViewProvider.newInstance();
    }

    public static <D> DataProvider<D> dataProvider() {
        return DataProvider.ofEmpty();
    }

    public static <D> DataProvider<D> dataProvider(D data) {
        return DataProvider.ofData(data);
    }

    public static <D> DataProvider<D> dataProvider(@NonNull List<D> list) {
        return DataProvider.of(list);
    }

    public static <K, V>MapDataProvider<K, V> mapProvider() {
        return MapDataProvider.of();
    }

    public static <K, V>MapDataProvider<K, V> mapProvider(@NonNull Map<K, V> map) {
        return MapDataProvider.of(map);
    }

    public static <K, V>MapDataProvider<K, V> mapProvider(K key, V value) {
        return MapDataProvider.of(key, value);
    }
}
